//
//  TabView.m
//  SinaWeiBo
//
//  Created by 姚建强 on 15-2-11.
//  Copyright (c) 2015年 com.yjq. All rights reserved.
//

#import "TabView.h"
#import "TabItemModel.h"
#import "TabItem.h"
@interface TabView()
{
    NSArray* items;
}
@end
@implementation TabView
-(void)clickSeletedItem:(UIButton *)btn{

    if ([self.delegate respondsToSelector:@selector(tabviewSeletedItem:)]) {
        [self.delegate tabviewSeletedItem:btn.tag];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
/*!
*  初始化
*
*  @param frame     frame
*  @param itemModels   TABItemModel数组
*
*/
- (id)initWithFrame:(CGRect )frame AndItemModels:(NSArray*) itemModels
{
    
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor=[UIColor whiteColor];
       CGFloat itemWidth = [[UIScreen mainScreen] bounds].size.width /[itemModels count];
        
        for (int i=0;i<[itemModels count];i++) {
               TabItemModel* model= itemModels[i];
            CGRect itemFrame=CGRectMake(itemWidth*i, 0, itemWidth, TABHIGHT);
            TabItem *item=[[TabItem alloc]initWithFrame:itemFrame Model:(TabItemModel*)model];
            [item setSignViewWithNum:i*5];
            [item setTag:i+1];
            [item addTarget:self action:@selector(clickSeletedItem:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:item];
            
        }
    }
    return self;
}

@end
